
import socket;
from threadpool import  ThreadPool,makeRequests;
import threading;



def handlerClientsocket(clientsocket):

    print(threading.current_thread().getName())
    msg = "欢迎访问";
    clientsocket.send(msg.encode("UTF-8"));
    clientsocket.close()

    pass;

def callback(*args, **kwargs):
    print(args);
    print(kwargs)
    pass;

# 创建socket对象
serversocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM);

# 获取本地主机名
host = socket.gethostname();
port = 9999;
# 绑定端口号
serversocket.bind((host,port));
# 设置最大连接数，超过后排队
serversocket.listen(5);
# 设置线程池大小为 10
pool = ThreadPool(5)
while True:
    # 建立客户端连接
    clientsocket,addr = serversocket.accept();
    print(clientsocket.__hash__())
    print("连接地址：%s" % str(addr));
    print(threading.current_thread().getName())
    requests = makeRequests(handlerClientsocket, (clientsocket,),callback);
    print(len(requests))
    pool.putRequest(requests.pop());







